package may.qf.service.impl;


import may.qf.entity.Emp;
import may.qf.mapper.EmpMapper;
import may.qf.service.EmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired
    private EmpMapper empMapper;

    @Override
    @Transactional
    public List<Emp> queryAll() {
        return empMapper.queryAll();
    }

    @Override
    public Emp queryByEmpNo(Integer empNo) {
        return empMapper.queryByEmpNo(empNo);
    }

    @Override
    public int update(Emp emp) {
        return empMapper.update(emp);
    }

    @Override
    public int insert(Emp emp) {
        emp.setCreateTime(new Date());
        return empMapper.insert(emp);
    }

    @Override
    public int delete(Integer empNo) {
        return empMapper.delete(empNo);
    }

    @Override
    public Emp login(Integer empNo, String name) {
        Emp emp = empMapper.queryByEmpNo(empNo);
        if (emp!=null && emp.getEname().equals(name)){
            return emp;
        }
        return null;
    }


}
